package ca.etsmtl.log730.projet.controller;

import java.util.UUID;

import org.apache.mina.core.future.DefaultWriteFuture;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IoSession;

public abstract class AbstractSessionController implements IoHandler {

	public AbstractSessionController(IoSession session, UUID sessionId) {
		super();
		this.session = session;
		this.sessionId = sessionId;
	}
	protected IoSession session;
	public void setSession(IoSession session) {
		this.session = session;
	}
	public void setSessionId(UUID sessionId) {
		System.out.println("SESSIONID = " + sessionId.toString());
		this.sessionId = sessionId;
	}
	public IoSession getSession() {
		return session;
	}
	public UUID getSessionId() {
		return sessionId;
	}
	protected UUID sessionId;
	
	public static void writeObject(final IoSession session, final Object o) {
//		session.write(o);
		
		new Thread(new Runnable() {
////
			@Override
			public void run() {
				DefaultWriteFuture dwf = new DefaultWriteFuture(session);
				dwf.getSession().write(o);
				dwf.awaitUninterruptibly();
			}
			
		}).start();
	}
}
